/**
 * 文件：CheckableFrameLayout.java
 * 包名：com.ronri.ams.sample;   --- 正式发布时需要修正
 * 说明：单选、多选样式控制
 * 作者：MS During
 * 日期：2017/5/11
 * 历史：
 */
package com.ronri.ams.sample;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Checkable;
import android.widget.FrameLayout;

public class CheckableFrameLayout extends FrameLayout implements Checkable {

    public CheckableFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    private boolean mChecked = false;

    @Override
    public void toggle() {
        setChecked(!mChecked);
    }

    @Override
    public boolean isChecked() {
        return mChecked;
    }

    @Override
    public void setChecked(boolean checked) {
        if (mChecked != checked) {
            mChecked = checked;
            refreshDrawableState();
            for (int i = 0, len = getChildCount(); i < len; i++) {
                View child = getChildAt(i);
                if (child instanceof Checkable) {
                    ((Checkable) child).setChecked(checked);
                }
            }
        }
    }
}
